export function format_time(ts){
    //return formatUnixtimestamp(parseInt(ts));
    ts = parseInt(ts);
    let now_morning = new Date(
        new Date(new Date().toLocaleDateString()).valueOf()
    );
    let yesterday = now_morning - 86400 * 1000;
    let thisMonday = (new Date()).valueOf() - ((new Date(now_morning)).getDay() - 1) * 86400 * 1000;
    let lastMonday = thisMonday - 7 *  86400 * 1000;
    if(ts > now_morning){
        var unixtimestamp = new Date(ts);
        var hour = "0" + unixtimestamp.getHours();
        var minute = "0" + unixtimestamp.getMinutes();
        return hour.substring(hour.length-2, hour.length) + ":"
            + minute.substring(minute.length-2, minute.length);
    }else if(ts > yesterday){
        var unixtimestamp = new Date(ts);
        var hour = "0" + unixtimestamp.getHours();
        var minute = "0" + unixtimestamp.getMinutes();
        return "昨天 "+hour.substring(hour.length-2, hour.length) + ":"
        + minute.substring(minute.length-2, minute.length);
    }else if(ts > thisMonday){
        let days = ["零","一","二","三","四","五","六","日"];
        var unixtimestamp = new Date(ts);
        var hour = "0" + unixtimestamp.getHours();
        var minute = "0" + unixtimestamp.getMinutes();
        return "星期" + days[(new Date(ts)).getDay()] + " " + +hour.substring(hour.length-2, hour.length) + ":"
        + minute.substring(minute.length-2, minute.length)
    }else if(ts > lastMonday){
        let days = ["零","一","二","三","四","五","六","日"];
        var unixtimestamp = new Date(ts);
        var hour = "0" + unixtimestamp.getHours();
        var minute = "0" + unixtimestamp.getMinutes();
        return "上周" + days[(new Date(ts)).getDay()] + " " + +hour.substring(hour.length-2, hour.length) + ":"
        + minute.substring(minute.length-2, minute.length)
    }else{
        var unixtimestamp = new Date(ts);
        var month = "0" + (unixtimestamp.getMonth() + 1);
        var date = "0" + unixtimestamp.getDate();
        var hour = "0" + unixtimestamp.getHours();
        var minute = "0" + unixtimestamp.getMinutes();
        return month.substring(month.length-2, month.length)  + "-" + date.substring(date.length-2, date.length)
        + " " + hour.substring(hour.length-2, hour.length) + ":"
        + minute.substring(minute.length-2, minute.length);
    }

}